<script src="../../famlinkapi/src/public/react_share/app/component/index.js"></script>
<template>
  <div class='homePage'
       :class="isShowComment ? 'swiper-no-swiping':''">
    <swiper-page :discoverData='discovers'/>
  </div>
</template>
<script>
  import { mapGetters, mapActions } from 'Vuex'
  import SwiperPage from '~/components/discover/SwiperPage.vue'
  import api from '../plugins/api'
  import { Toast } from 'mint-ui'

  const Cookie = process.browser ? require('js-cookie') : undefined

  export default {
    layout: 'raindrop',
    components: {
      SwiperPage
    },
    asyncData({ req }) {
      return {}
    },
    data() {
      return {
        discover: []
      }
    },
    computed: {
      ...mapGetters([
        'isShowComment',
        'sid',
        'discoverData'
      ]),
      discovers() {
        return this.discoverData || this.discover
      }
    },
    created() {
      if (!this.discoverData) {
        this._renderDiscover(1)
      }
    },
    mounted() {
    },
    methods: {
      async _renderDiscover(refresh) {
        const sid = Cookie.get('sid')
        this.$store.commit('_setSid', sid)
        const params = {
          sid: sid,
          refresh: refresh || 0,
          pagesize: 10
        }
        const res = await api.getDiscover(params)
        // console.log(res)
        if (res.status == 0) {
          this.discoverData = res.data
          this.$store.commit('_setdiscoverData', res.data)
        } else {
          Toast(res.info)
        }
      }
    }
  }
</script>
<style scoped lang="scss">
  .homePage {
    width: 100%;
    height: calc(100% - 109px);
  }


</style>
